package com.martin.lib_base.net.adapter

import com.google.gson.Gson
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory
import com.google.gson.reflect.TypeToken
import com.martin.lib_base.ktx.loge

class NullAdapterFactory : TypeAdapterFactory {
    override fun <T : Any?> create(gson: Gson, type: TypeToken<T>): TypeAdapter<T>? {
        return when (type.rawType) {
            String::class.java -> StringTypeAdapter() as TypeAdapter<T>
            Int::class.java -> IntTypeAdapter() as TypeAdapter<T>
            Double::class.java -> DoubleTypeAdapter() as TypeAdapter<T>
            Long::class.java -> LongTypeAdapter() as TypeAdapter<T>
            Boolean::class.java -> BooleanTypeAdapter() as TypeAdapter<T>
            else -> {
                null
            }
        }
    }
}